package com.tiger.cloud.controller.crm;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.tiger.cloud.common.mybatis.BaseController;
import com.tiger.cloud.form.RegionsForm;
import com.tiger.cloud.model.crm.Regions;
import com.tiger.cloud.service.crm.IRegionsService;
import com.tiger.cloud.service.system.CommonRegions;
import com.tiger.cloud.util.Response;
import com.tiger.cloud.util.ResponseUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 区域表
 */
@Controller
@RequestMapping(value = "regions")
@Api(value = "省市区地区",tags = "区域")
public class RegionsController extends BaseController {

	@Autowired
	private IRegionsService regionsService;
	
	/**
	 * 获取省市区三级联动列表
	 * @param regionsForm
	 * @return
	 */
	@RequestMapping(value = "get", method = RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	@ApiOperation(value = "获取省市区三级联动列表",notes = "获取省市区三级联动列表")
	public Response list(@RequestBody RegionsForm regionsForm){
		if(regionsForm.getType()==2 && regionsForm.getpRegionId()!=null){//市
			return ResponseUtil.ok(CommonRegions.getCitys(regionsForm.getpRegionId()));
		}else if(regionsForm.getType()==3 && regionsForm.getpRegionId()!=null){//区
			return ResponseUtil.ok(CommonRegions.getDistricts(regionsForm.getpRegionId()));
		}
		return ResponseUtil.ok(CommonRegions.getProvices());//省
	}
	
//	/**
//	 * 获取省市区三级联动列表
//	 */
//	@RequestMapping(value = "tree", method = RequestMethod.POST)
//	@ResponseBody
//	@ApiOperation(value = "增量获取省市区三级联动列表",notes = "增量获取省市区三级联动列表")
//	public Response tree(@RequestBody Regions region){
//		List<Regions> regions =	regionsService.find(region);
//		tree
//		return ResponseUtil.ok(regions);//省
//	}
//	
	/**
	 * 获取省市区三级联动列表
	 */
	@RequestMapping(value = "incrementRegions", method = RequestMethod.POST)
	@ResponseBody
	@CrossOrigin
	@ApiOperation(value = "增量获取省市区三级联动列表",notes = "增量获取省市区三级联动列表")
	public Response incrementRegions(@RequestBody Regions region){
		List<Regions> regions =	regionsService.find(region);
		return ResponseUtil.ok(regions);//省
	}

}